﻿#ifndef PROPERTY_DATA_H
#define PROPERTY_DATA_H
#define INSUL_NUM_MAX 62
typedef struct      // 附录C
{
    double id;
    char province[20];
    char city[20];
    double ta_year;     //保温常年运行
    double ta_day_5;    //采暖季运行
    double ta_day_8;    //采暖季运行
    double ta_month_h;  //防烫
    double ta_ac;       //防结露
    double ta_lowest;   //防冻
    double ta_highest;
    double phi;         //防结露
    double w_winter_m;
    double w_winter;
    double w_summer;
    char styear[10];
} CTYW;

typedef struct
{
    unsigned int id;
    char name[40];
    char remark[20];
    unsigned int density_min;
    unsigned int density_max;
    int allowTemperature_min;
    int allowTemperature_max;
    int reTemperature_min;
    int reTemperature_max;
    double tc0;
    int tm_min;
    int tm_max;
    double a;
    double b;
    double c;
    double d;
    double e;
    double f;
    double g;
    double strength;
    double strength_196;
} Insul;
typedef struct
{
    unsigned int id;
    char stressCode[20];
    char ShapeCode[20];
    char MClass[50];
    char ClassCode[20];
    char pipeName[40];
    char weldingCode[20];
    char pipeCode[20];
    char MCode[25];
    char process[20];
    unsigned int thickness_min;
    unsigned int thickness_max;
    char temperature_min[20];
    unsigned int rm;
    unsigned int rel;
    unsigned int temperature_max;
    double stress[36];
    double stress_tmax;
    char remark[20];
} PipeMaterialProperties;

template<typename T>
int getPropertyData(const char* pFile, T* st, int pos, int count)
{
	char* pFullFileName = GetFullFileName(pFile);
	
    FILE* fp;
    errno_t err = 0;
    err = fopen_s(&fp, pFullFileName, "rb");
    if (err)
    {
        printf("open '%s' failed\n", pFullFileName);
        return -1;
    }
    else
    {
        fseek(fp, 0, SEEK_END);
        if (0 == count)
            count = (ftell(fp) - sizeof(*st) * pos) / sizeof(*st);
        fseek(fp, sizeof(*st) * pos, SEEK_SET);

        int row = fread(st, sizeof(*st), count, fp);
        fclose(fp);
        return row;
    }
}

extern CTYW* pCtyw;
extern Insul* pInsul;
extern PipeMaterialProperties* pPmp;

CTYW* SetCurrentCtyw(char* city);
PipeMaterialProperties* SetCurrentPmp(unsigned int id);
Insul* SetCurrentInsul(unsigned int id, double tm);

char* LPWSTRToChar(wchar_t* lpwszBuf);

char* GetExePath();

char* GetFullFileName(const char* pFileName);

extern const char componentList[121][5][255];
#endif